//
import 'package:flutter/material.dart';
import '../model/home_model.dart';
import 'fwebview.dart';


class salesBox extends StatelessWidget {
  final  SalesBoxModel salesBoxModel;
  const salesBox({super.key,required this.salesBoxModel});

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(6),
        color: Colors.white,
      ),
      child: _items(context),

    );
  }

  Widget _items(BuildContext context){

    return Container(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(6),
      ),
      child: Column(
        children: [
          Container(
            height: 44,
            decoration: BoxDecoration(
              color: Colors.white,
                border:Border(
                  bottom: BorderSide(width: 1,color: Color(0xfff2f2f2)),
                )
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
               children: [
                 Container(
                   margin: EdgeInsets.only(left: 10),
                   child: Image.network(
                     salesBoxModel?.icon ?? "",
                     fit: BoxFit.fill,
                     height: 15,
                   ),
                 ),

                 Container(
                   margin: EdgeInsets.only(right: 10),
                   padding: EdgeInsets.fromLTRB(10, 2, 10, 2),
                   decoration: BoxDecoration(
                     borderRadius: BorderRadius.circular(12),
                     gradient: LinearGradient(
                       colors: [ Color(0xffff4e63), Color(0xffff6cc9),],
                       begin: Alignment.centerLeft,
                       end: Alignment.centerRight,
                     )
                   ),
                   child: GestureDetector(
                     onTap: (){
                       Navigator.push(context,MaterialPageRoute(builder: (context) => FWebView(url: salesBoxModel?.moreUrl,)));
                     },
                     child: Text('获取更多福利 >',style: TextStyle(fontSize: 12,color: Colors.white),),

                   ),
                 ),
               ],
            ),
          ),
         Row(
          children: [
            _item(context,salesBoxModel?.bigCard1,true,true,false),
            _item(context,salesBoxModel?.bigCard2,true,false,false),
          ],
         ),
          Row(
            children: [
              _item(context,salesBoxModel?.smallCard1,false,true,false),
              _item(context,salesBoxModel?.smallCard2,false,false,false),
            ],
          ),
          Row(
            children: [
              _item(context,salesBoxModel?.smallCard3,false,true,true),
              _item(context,salesBoxModel?.smallCard4,false,false,true),
            ],
          ),
        ],
      ),
    );

  }

  Widget _item(BuildContext context,CommonModel? e,bool isBig,bool isLeft,bool islastRow){
    BorderSide borderSide = BorderSide(width: 1,color: Color(0xfff2f2f2));
      return GestureDetector(
        onTap: (){
          Navigator.push(context,MaterialPageRoute(builder: (context) => FWebView(url: e?.url,title: e?.title,statusBarColor: e?.statusBarColor,hideAppBar: e?.hideAppBar,)));
        },
        child: Container(
          decoration: BoxDecoration(
            color: Colors.white,
            border: Border(
              right: isLeft ? borderSide : BorderSide.none,
              bottom:islastRow ?  BorderSide.none : borderSide,
            )
          ),
          child: Image.network(
            e?.icon ?? "",
            fit: BoxFit.fill,
            width: MediaQuery.of(context).size.width / 2 - 15,
            height: isBig ? 129 : 80,
          ),
        ),
      );

  }
}




